<div class="page-header">
    <h1>
        用户包裹交易记录
        <small>
            <i class="ace-icon fa fa-angle-double-right"></i>
        </small>
    </h1>
</div>
<div class="row">
    <div class="col-xs-12">
        <table id="dtpPackageTrade" class="dataTable">
            <tfoot>
            <tr>
                <td colspan="6">本页合计：</td>
                <td>
                    <span name="Trade_Num" class="tooltip-"/>
                </td>
                <td colspan="3"></td>
            </tr>
            </tfoot>
        </table>
        <div id="dtpPackageTrade_filter" class="dataTables_filter">
            <div>
                <select id="dtpPackageTrade_F_SType" class="selectpicker" data-style="btn btn-info btn-sm" data-width="90px">
                    <option value="">模糊查询</option>
                    <option data-divider="true"></option>
                    <option value="User_ID">用户ID</option>
                    <option value="User_NickName">用户昵称</option>
                    <option value="Item_Name">物品名称</option>
                    <option value="Trade_Order_No">相关单据号</option>
                </select>
                <input id="dtpPackageTrade_F_SValue" class="fvalue" type="text"/>

                <input id="dtpPackageTrade_F_StartDate" type="text" style="width: 76px;" placeholder="交易时间">
                <label>-</label>
                <input id="dtpPackageTrade_F_EndDate" type="text" style="width: 76px;" placeholder="结束时间">
                <select id="dtpPackageTrade_F_SelectDate"></select>
                <input id="dtpPackageTrade_F_ItemID" type="text" placeholder="物品ID"/>
                <select id="dtpPackageTrade_F_ItemType" style="width: 100px;" data-databind="UserPackageItemType" placeholder="物品类型…"></select>
                <select id="dtpPackageTrade_F_TradeType" style="width: 140px;" data-databind="UserPackageTransaction" placeholder="交易类型过滤…"></select>
                <button id="dtpPackageTrade_F_Btn"></button>
            </div>
        </div>
    </div>
</div>
<script src="<%- Virtual_Path.Static %>jquery.plugin/dataTables/jquery.dataTables.min.js"></script>
<script src="<%- Virtual_Path.Static %>jquery.plugin/dataTables/jquery.dataTables.bootstrap.min.js"></script>
<script>
    $(function () {
        //region 时间输入框插件
        $('#dtpPackageTrade_F_StartDate, #dtpPackageTrade_F_EndDate').datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            minView: 2,
            autoclose: true
        });
        //endregion
        //region 绑定日期选择框
        $.KOC.Date.Select.Bind({
            eSelect: $('#dtpPackageTrade_F_SelectDate'),
            eBegin: $('#dtpPackageTrade_F_StartDate'),
            eEnd: $('#dtpPackageTrade_F_EndDate')
        });
        //endregion
        //region dtpPackageTrade
        $("#dtpPackageTrade").dataTable({
            'aoColumns': [
                {
                    'sWidth': '120px', 'data': 'Trade_Order_No', 'sName': 'Trade_Order_No', 'sTitle': "相关单据号", 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        $(td).html($('<a/>').attr('data-openwindow', cellData).text(cellData));
                    }
                },
                {
                    'data': 'User_NickName', 'sTitle': '用户昵称', 'sClass': 'r-left', 'bSortable': false,
                    'createdCell': function (td, cellData, rowData) {
                        $(td).html($('<a class="tooltip-" data-rel="tooltip" data-original-title="用户ID：'+ rowData.User_ID + '"/>').attr('data-openwindow', ':UserInfo:' + rowData.User_ID).html(cellData));
                    }
                },
                {
                    'sWidth': '110px', 'data': 'Item_Type', 'sName': 'Item_Type', 'sTitle': "物品类型", 'sClass': 'center'
                },
                {
                    'sWidth': '80px', 'data': 'Item_Name', 'sName': 'Item_Name', 'sTitle': '物品名称', 'sClass': 'r-left',
                    'createdCell': function (td, cellData, rowData) {
                        $(td).html('<span class="tooltip-" data-rel="tooltip" data-original-title="物品ID：' + rowData.Item_ID + '">' + cellData + '</span>');
                    }
                },
                {
                    'sWidth': '110px', 'data': 'Trade_Type_Name', 'sName': 'Trade_Type', 'sTitle': "交易类型", 'sClass': 'center'
                },
                {
                    'sWidth': '80px', 'data': 'Trade_Flag', 'sTitle': '方式', 'sClass': 'center', 'bSortable': false,
                    'createdCell': function (td, cellData) {
                        switch (cellData) {
                            case -1:
                                $(td).html('<span class="label label-danger"><i class="fa fa-sign-out"></i> 出帐</span>');
                                break;
                            case 1:
                                $(td).html('<span class="label label-success"><i class="fa fa-sign-in"></i> 入帐</span>');
                                break;
                        }
                    }
                },
                {
                    'sWidth': '85px', 'data': 'Trade_Num', 'sName': 'Trade_Num', 'sTitle': "交易数量", 'sClass': 'center t-right',
                    'createdCell': function (td, cellData, rowData) {
                        switch (rowData.Trade_Flag) {
                            case -1:
                                $(td).html('-' + cellData);
                                break;
                            case 1:
                                $(td).html(cellData);
                                break;
                        }
                    }
                },
                {
                    'sWidth': '6%', 'data': 'Num', 'sName': 'Num', 'sTitle': "剩余", 'sClass': 'center t-right'
                },
                {
                    'sWidth': '15%', 'data': 'Remark', 'sName': 'Remark', 'sTitle': "备注", 'sClass': 'center t-left'
                },
                {
                    'sWidth': "140px", 'data': 'Create_Date', 'sName': 'Create_Date', 'sTitle': "交易时间", 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        $(td).text(moment(cellData).isValid() ? moment(cellData).format('YY/MM/DD HH:mm:ss') : "");
                    }
                }
            ],
            'aaSorting': [0, 'desc'],
            'sAjaxSource': '/ajax/user.page.userpackagetrade',
            'fnServerParams': function (aoData) {
                if (!this.arrPageFilter) {
                    this.arrPageFilter = {
                        F_StartDate: $(this.selector + '_F_StartDate').val(),
                        F_EndDate: $(this.selector + '_F_EndDate').val(),
                        F_ItemID: $(this.selector + '_F_ItemID').val(),
                        F_ItemType: $(this.selector + '_F_ItemType').val(),
                        F_TradeType: $(this.selector + '_F_TradeType').val()
                    };
                    switch (this.arrPageFilter.F_TradeType) {
                        case 'in':
                            this.arrPageFilter.F_TradeFlag = 1;
                            break;
                        case 'out':
                            this.arrPageFilter.F_TradeFlag = -1;
                            break;
                        default:
                            this.arrPageFilter.F_TradeFlag = 0;
                            break;
                    }
                } else {
                    $(this.selector + '_F_StartDate').val(this.arrPageFilter.F_StartDate);
                    $(this.selector + '_F_EndDate').val(this.arrPageFilter.F_EndDate);
                    $(this.selector + '_F_ItemID').val(this.arrPageFilter.F_ItemID);
                    $(this.selector + '_F_ItemType').select2('val', this.arrPageFilter.F_ItemType || '-1');
                    $(this.selector + '_F_TradeType').select2('val', this.arrPageFilter.F_TradeType || '-1');
                }
                this.ofnServerParams(aoData);
            },
            'fnFooterCallback': function (nFoot, aData) {
                var _Trade_Num = 0;
                _.forEach(aData, function (ThisValue) {
                    _Trade_Num += ThisValue.Trade_Flag * ThisValue.Trade_Num;
                });
                $(nFoot).find('[name="Trade_Num"]').text(_Trade_Num);
            },
            'fnDrawCallback': function () {
                $.Common.Bootstrap.Tooltip(this);
                this.ofnDrawCallback();
            }

        });
        //endregion
    })
</script>